package com.rran.study.designpattern.behavioral.strategy.strategy.spring;

import com.rran.study.designpattern.behavioral.strategy.annotation.PayAction;
import com.rran.study.designpattern.behavioral.strategy.factory.PayActionRepository;
import com.rran.study.designpattern.behavioral.strategy.strategy.PayStrategy;
import org.springframework.beans.factory.InitializingBean;

/**
 * @author yy
 * @Type AbstractPayStrategy.java
 * @Desc 支付抽象类
 * @date 2020/7/20 12:47
 */
public abstract class AbstractPayStrategy implements PayStrategy, InitializingBean {

    @Override
    public void afterPropertiesSet() {
        PayAction payAction = getClass().getAnnotation(PayAction.class);
        if (payAction == null) {
            throw new RuntimeException("strategy must be with annotation PayAction");
        }
        String payName = payAction.payName();
        PayActionRepository.storeStrategy(payName, this);
    }
}
